

fn = FILE_SEARCH('./local/hht_2011/FIXME/*FIXME*fits',count=n)
print,n


FOR i=0L, n-1,2 DO BEGIN
;FOR i=48, 48, 2 DO BEGIN   
   sH = readfits(fn[i],hH)
   sV = readfits(fn[i+1],hV)
   
   sxaddpar,hH,'RESTFREQ','0.2795118379000E+12'
   sxaddpar,hV,'RESTFREQ','0.2795118379000E+12' 
   sxaddpar,hH,'CRVAL1',(-279.5118379d9 + 279.5576259d9)
   sxaddpar,hV,'CRVAL1',(-279.5118379d9 + 279.5576259d9)
   sxaddpar,hH,'LINE','N2HP(3-2)   '
   sxaddpar,hV,'LINE','N2HP(3-2)   '
   
   vH = v_from_hdr(hH)
   vV = v_from_hdr(hV)
   
   plot,vH,sH,yr=[-0.5,1.5],title='',xr=[-100,200]
   oplot,vV,sV+1,color=cgColor('Sky Blue')
   
   yfit = MPFITPEAK(vH,sH,A, NTERMS=3, /POSIT)
   vline,A[1],color=cgColor('Yellow'),linestyle=2
   al_legend,position=[A[1],-0.35],[string(A[1],format="(F0.1)")],$
             textcolor=cgColor('Yellow')
   
   ;; Write out files on top of original ones in the fitsfile/
   ;; directory

   fnH = strmid(fn[i],0,strpos(fn[i],'FIXME',/REVERSE_SEARCH))+strmid(fn[i],strpos(fn[i],'_N2'))

   fnV = strmid(fn[i+1],0,strpos(fn[i+1],'FIXME',/REVERSE_SEARCH))+strmid(fn[i+1],strpos(fn[i+1],'_N2'))

   dirpos = strpos(fnH,'FIXME')
   fnH = strmid(fnH,0,dirpos) + strmid(fnH,dirpos+6)
   fnV = strmid(fnV,0,dirpos) + strmid(fnV,dirpos+6)
   
   print,fn[i]
   print,fn[i+1]
   print,fnH
   print,fnV
   

   writefits,fnH,sH,hH
   writefits,fnV,sV,hV
   
ENDFOR

END
